<div class="section">

	<div class="section-title">
    	
    		Quản lý trả báo
        
    </div>
    
    <div class="section-content">
    	<div class="button right">
 		<?php if($_GET['print'] !="true" ){ ?>
        	<a class="button print" id="btnPrint">In danh sách</a>
        	<?php if($list_button['insert']){ ?>
        	<a class="button add" href="<?php echo $insert?>">Thêm mới</a>
            <?php } ?>
            <?php if($list_button['delete']){ ?>
            <a class="button delete" onclick="deleteItem()">Xóa</a>
            <?php } ?>
        <?php } ?>
        </div>
        <div class="clearer">&nbsp;</div>
        
        <form action="" method="post" id="listitem" name="listitem">
        <?php if($_GET['print'] !="true" ){ ?>
        	<div id="ben-search">
            	<table>
                	<tr class="left">
                    	<td>
                            <label>Ngày lập:  </label>
                            <label>Từ ngày </label>
                            <input type="text" id="tungay" name="tungay" class="text ben-datepicker" />
                            <label>Đến ngày </label>
                            <input type="text" id="denngay" name="denngay" class="text ben-datepicker" />
                		</td>
                	</tr>
                    <tr class="clearer"><td></td></tr>
                    <tr class="left">
                        <td>
                            <label>Loại báo:</label>
                            <select id="loaibaoid" name="loaibaoid">
                                <option value="">Chọn loại báo</option>
                                <?php foreach($loaibaos as $val){ ?>
                                <option value="<?php echo $val['loaibaoid']?>"><?php echo $val['tenloaibao']?></option>
                                <?php } ?>
                            </select>
                            <label>Kỳ báo</label>
                            <select id="kybaoid" name="kybaoid">
                                <option value="">Chọn kỳ báo</option>
                            </select>
                		</td>
                    	<td>
                            <!--<label>Người trả:</label>
                            <select id="nhanvientraid" name="nhanvientraid">
                                <option value="">Chọn nhân viên</option>
                                <?php foreach($nhanviens as $val){ ?>
                                <option value="<?php echo $val['nhanvienid']?>"><?php echo $val['hoten']?></option>
                                <?php } ?>
                            </select>
                            <label>Khu vực trả:</label>
                            <select id="khuvuctraid" name="khuvuctraid">
                                <option value="">Chọn khu vực</option>
                                <?php foreach($khuvucs as $khuvuc){ ?>
                                <option value="<?php echo $khuvuc['khuvucid']?>"><?php echo $this->string->getPrefix("&nbsp; &nbsp; &nbsp; &nbsp;",$khuvuc['level']);?><?php echo $khuvuc['tenkhuvuc']?></option>
                              <?php }?>
                            </select>
                            <br />
                            <label>Người nhận:</label>
                            <select id="nhanviennhanid" name="nhanviennhanid">
                                <option value="">Chọn nhân viên</option>
                                <?php foreach($nhanviens as $val){ ?>
                                <option value="<?php echo $val['nhanvienid']?>"><?php echo $val['hoten']?></option>
                                <?php } ?>
                            </select>
                            
                            <label>Khu vực nhận:</label>
                            <select id="khuvucnhanid" name="khuvucnhanid">
                                <option value="">Chọn khu vực</option>
                                <?php foreach($khuvucs as $khuvuc){ ?>
                                <option value="<?php echo $khuvuc['khuvucid']?>"><?php echo $this->string->getPrefix("&nbsp; &nbsp; &nbsp; &nbsp;",$khuvuc['level']);?><?php echo $khuvuc['tenkhuvuc']?></option>
                              <?php }?>
                            </select>               
                            <br />-->
                            <a class="button-other search" onClick="searchForm()">Tìm</a>
                            <a class="button all" href="?route=deliman/phieutrabao">Xem tất cả</a>
                		</td>
                	</tr>
                </table>
            </div>
       <?php } ?>
            <div class="clearer">^&nbsp;</div>
            <div id="container">
            	
                <div id="fragment-phieudalap">
                    <table class="data-table" cellpadding="0" cellspacing="0">
                    <tbody>
                        <tr class="tr-head">
                            <th width="1%"><input class="inputchk" type="checkbox" onclick="$('input[name*=\'delete\']').attr('checked', this.checked);"></th>
                            <th>Ngày lập</th>
                            <th>Số phiếu</th>
                            <th>Người trả báo</th>
                            <th>Khu vực trả</th>
                            <th>Người nhận báo</th>
                            <th>Khu vực nhận</th>
                            <th>Loại báo</th>
                            <th>Kỳ báo</th>
                            <th>Ngày phát hành</th>
                            <th>Số lượng trả</th>
                            
                            <th>Control</th>                                  
                        </tr>
            
            
            <?php
                foreach($datas as $item)
                {
            ?>
                        <tr>
                            <td class="check-column"><input class="inputchk" type="checkbox" name="delete[<?php echo $item['phieutrabaoid']?>]" value="<?php echo $item['phieutrabaoid']?>" ></td>
                            
                            
                            <td><?php echo $this->date->formatMySQLDate($item['ngaylap'])?></td>
                            <td><?php echo $item['maphieutrabao']?></td>
                            <td><?php echo $this->document->getNhanVien($item['nhanvientraid'])?></td>
                            <td><?php echo $this->document->getKhuVuc($item['khuvuctraid'])?></td>
                            <td><?php echo $this->document->getNhanVien($item['nhanviennhanid'])?></td>
                            <td><?php echo $this->document->getKhuVuc($item['khuvucnhanid'])?></td>
                            <td><?php echo $item['tenloaibao']?></td>
                            <td><?php echo $item['tenkybao']?></td>
                            <td><?php echo $this->date->formatMySQLDate($this->document->getKyBao($item['kybaoid'],'ngayphathanh'))?></td>
                            <td class="number"><?php echo $this->string->numberFormate($item['soluongtra'])?></td>
                            <td class="link-control">
                                <?php if($list_button['update']){ ?>
                                <a class="button edit" href="<?php echo $item['link_edit']?>">Sửa</a>
                                <?php } ?>
                            </td>
                        </tr>
            <?php
                }
            ?>
                            
                                                        
                    </tbody>
                    </table>
                </div>
                
                
            </div>
                
        	<?php echo $pager?>
        
        </form>
        
    </div>
    
</div>
<script language="javascript">

function deleteItem()
{
	var answer = confirm("Bạn có muốn xóa không?")
	if (answer)
	{
		$.post("?route=deliman/phieutrabao/delete", 
				$("#listitem").serialize(), 
				function(data)
				{
					if(data=="true")
					{
						alert("Xóa thành công");
						window.location.reload();
					}
				}
		);
	}
}

function searchForm()
{
	var url =  "?route=deliman/phieutrabao";
		
	if($("#tungay").val() != "")
		url += "&tungay="+ $("#tungay").val();
	if($("#denngay").val() != "")
		url += "&denngay=" + $("#denngay").val();
	if($("#loaibaoid").val() != "")
		url += "&loaibaoid=" + $("#loaibaoid").val();
	if($("#kybaoid").val() != "")
		url += "&kybaoid=" + $("#kybaoid").val();
	/*if($("#nhanvientraid").val() != "")
		url += "&nhanvientraid=" + $("#nhanvientraid").val();
	if($("#nhanviennhanid").val() != "")
		url += "&nhanviennhanid=" + $("#nhanviennhanid").val();
	if($("#khuvuctraid").val() != "")
		url += "&khuvuctraid=" + $("#khuvuctraid").val();
	if($("#khuvucnhanid").val() != "")
		url += "&khuvucnhanid=" + $("#khuvucnhanid").val();*/
	
	window.location = url;
}
// Giu cho cac field tim kiem van ko doi
$("#tungay").val("<?php echo $_GET['tungay']?>");
$("#denngay").val("<?php echo $_GET['denngay']?>");
$("#loaibaoid").val("<?php echo $_GET['loaibaoid']?>");
$("#kybaoid").val("<?php echo $_GET['kybaoid']?>");
$("#nhanvientraid").val("<?php echo $_GET['nhanvientraid']?>");
$("#nhanviennhanid").val("<?php echo $_GET['nhanviennhanid']?>");
$("#khuvuctraid").val("<?php echo $_GET['khuvuctraid']?>");
$("#khuvucnhanid").val("<?php echo $_GET['khuvucnhanid']?>");
$('#loaibaoid').change(function(e) {
	$.getJSON('?route=deliman/kybao/getKyBao&col=loaibaoid&val='+$('#loaibaoid').val(),function(data){
		str = '<option value="">Chọn tất cả</option>';
		for(i in data.kybaos)
		{
			str += '<option value="'+ data.kybaos[i].kybaoid +'">'+ data.kybaos[i].tenkybao +'</option>';
		}
		$('#kybaoid').html(str);
		$('#kybaoid').val("<?php echo $_GET['kybaoid']?>");			
	})
   /* $('#kybaoid').load('?route=deliman/phieuphanphoi/getKyBaos&loaibaoid='+$('#loaibaoid').val(),function(){
		$('#kybaoid').val("<?php echo $_GET['kybaoid']?>");	
		$('#kybaoid').change();
	});*/
});
$(document).ready(function(e) {
    $('#loaibaoid').change();
});

$('#btnPrint').click(function(){
	var url = window.location+"&print=true";
	 var result = window.showModalDialog(url,"", "dialogWidth:1000px; dialogHeight:450px; center:yes");
});
</script>

<?php if($_GET['print'] =="true" ){ ?>
	<script language="javascript">
        window.print();
    </script>
<?php } ?>